Tests and minor fixes