Restructure app and add unit tests