a bit refactoring, small logic change too.