figing code standard and some refactorings