Loads of changes to make the app work as expected and more maintainable.