fixed with ugliest code I have ever seen