having problems with cleaning up code