refactoring (probably broken)