Fix OS-dependent parts
Tidy imports, spacing, comments, etc.
Move platform-dependent stuff to the top