Refactoring some code conditions