Final working code.
Resolved conflicts, final working code.