codecleaning, improvements and tests