cleaned up and fixed the code