Move sys imports to the top of the file

Replaces multiple inline imports with one at the top of the file, keeping all stdlib imports together.