All these tutorials are relevant to what you are doing:
Using millis for timing Demonstration for several things at the same time Finite state machine tutorial