use ... instead of apply in a few places
use `if-else` as an enhanced replacement for `if`