Fix some warnings and code cleanup