wide ranging bug fixing and implementation