Clean up and reduce size of library, trim API down to minimal interface, fix scan() function