even more functions copied from scanner.c