refactoring to some extent