Small improvements and added some tests