fixed missing check and made some other changes