[#346] Refactor; fix tests slightly