Reworked and extended much more towards gen_fsm similarity