Make modals close on backdrop click, refactor modal code