Mild refactoring

For performance improvement & fixing code style