changed constructor to allow key to be passed