Added preconditions to the functions.