refactoring and "coding style" cleanup