added a much better solution