This feels like magic. Is there a better way to handle this?