cleaned up source, added comments