Code cleanup and factorization. Create generic manipulator class.