Moved some functions here from ssvu