Cleaned up source and added comments everywhere.