Somehow working implementation