Cleaning up the code, fixed some issues that made the app crash