This function could be combined with the one below, but at this point I don't really care