Change 'guint' variables to 'gint' and add valid geometry check