Fixed bug with results not returned. Also added pdb trace