Added comments and some missing conditions