Updated code

Improved robustness of app, 9/18/14 evening by Zain