Made small modifications to code format and some refactoring