refactoring / fixing erros