Added comments and precondition checks.