Preliminary implementation of import and a couple of bug fixes