Fixed bugs in scan doc handler
Tidied Up
Tidied up