Trying to fix broken code - this is hell