refactored, but no major changes
more minor edits