refactor madness