cleaned up code; final draft