cleaning up code, fixing bug