Fix logic in datatype chooser
clean up code