[#2]: Fixed logic of determine_unit_and_type

Fixed implementation of determine_unit_and_type, added unit test for it.