added some comments because who the hell knows how this works