refactored names, added useful comments, cleaned up code