reimplemented with the switch as suggested