restructuring app and fixing errors