Cleaned up old code, added a few comments