Full code rework - initial commit