added comments and fixed small issues