fixed some errors in the logic from my last commit, also some minor indentation fixes