Style tweaks and some refactoring