Refactored further, fixed Safari bug.