Move this mess into a separate file