edited to improve
mostly done