optimize constructor's code