Cleanup of implementation & performance improvements.