adding back in relevant changes from reverted branch