Cleanup + some unit tests