made code much more readable, with comments, and deleted some nonsense