Adding mock test and refactoring