added further modification and code clean ups