WIP: Tests and fixes for issues uncovered by testing