some refactoring and layout improvements