various bug fixing