refactor to make the app working