Code cleanup
Portability fixes