refactored to allow for multiple concurrent uses with new objects, cleaned up code a little, added comments