re-factored, back button mostly working, thanks to marc+joe