code refactored - equals condition put first