Rewrote classes to make more readable, bug fixes