code clean up to use delgate