did a much simpler implementation, check notes for more information