added comments and some extra functionality