Added comments and error-checks