clean up code, still not doing the right thing though