more logic refactoring