small improvements, added some tests