code clean up and few improvements