Cleaned up code cruft and added a bit of documentation