Functions now in order, test cases at the very end.