updating condition testing and fixing some bugs