Scan function works, but there are bugs.