Better conditional logic and removed debug print