some cleaning code and improvement