move init code into init function