refactoring
revert to almost original version