Added comments and simplified