start of reworking borrowed code
continued of reworking borrowed code
continued of reworking borrowed code