few improvements and tests