cleaned up code (working)