updated with refactoring