Added a bunch of features, cleaned up code