moved some code into init function