Recommitted Code cleanup with code fixes

See: 67882e3ae0b9a7c536b6f8d658d1704fdc8df118