Moved functionality into BaseDocument, and fixed bug in view code