Removed reversing, beautified the code a bit