Code cleanup, added comments, removed old code