Cleanup of various bugs and warnings