Move global import handling to Reader, also refactor some code.