completed working implementation