Working code of app...simulation bug found