merged #31 and #22 with rspeed suggestion