minor edits, mainly code refactoring