my implementation of famous cell finite machine