Tried pulling function out