Fix horribly broken code