changed logic and some log messages