New version with modifications discussed with @humanHardDrive