Add function call expectations and some refactoring