Add inline comments, cleaned up code