Clean up code and fix GTK errors