Did some refactoring

Flip did some refactoring