cleaned up the code and fixed the thing