Fix variable scope and grab ids directly from hash