Added timer to change output. Lots of refactoring