Initial cleanup and reimplementation