Various fixes. Also, DRY!