support more codes
better parameter checking
unneeded default case
fix formatting