code is working but not satisfying conditions