cleaned up code, working