Cleaned code up a bit, added more documentation, removed unneeded imports