added viewer and tidied up a bit