Refactor Start

Start of Refactoring of code for readability and speed.