cleaning code and improved performance