patched several bugs