Switch replaced with simpler code