Some code refactoring according to best practises