Less hacky implementation of previous fixes