Bug fixes to make it work with local scan