updated comments and cleaned up code