clean up code, seems to be working