moved code into constructor