refactored bad bad implementation