separate constructor functions and move to lib