Refactoring

Integrate rubocop and do some refactoring. All functionals tests passed.