some refactoring and fixed code violations