finalised scanner, fixed bugs