improvements and bug fixing