Refactor like hell and make it work