refactored according to master