added parameter for verbose, supporting function #4
refactor code to make code nicer to read