refactoring a little bit and removing unused functions