refactoring nearly done