fix appears require fatal error
add switch code and more tests