cleaned up implementation