Cleaned up code, added notes