improve constructor code