bug fixing, not fully tested