Fixed logic, documented it in notes and tests