Some refactoring.

Did some code refactoring.