tidying some code and unused variables