cleaned up source and added comments