Reduce 2 functions to 1, streamline a bit