Cleanup and tests

[merge]