logic mistakes in my last commit fixed