bug fixes for pi code