fixed checking conditions