added comments and some doc in the code