added comments and code documentation