Various changes and bug fixing