logic changes to fix bugs