changed return value and added a preconditions check