Major optimizations to the modals and JavaScript. Cleans up backend a bit also.