Move import os to before each time it is used to avoid weird error that it isn't imported when we use it.
(#430)