append ifelse commands and rewrite serialization