Fixes and cleanup

This fixes a few warnings and errors and does a general code cleanup.