Cleaned up implementation.