Added comments and code cleaning