added comments and removed legacy code