Cleaned up code and added more comments for reference to developers