Fix compatibility and bugs