A much better way of doing this