code cleanup and commented