cleanup code and remove unused variables