Ported stuff from older frosk version.