Cleaned up implementation