Ugliest code ever