Update app.c

new code and cleanup