First complete working implementation