Extracted some functions, not really sure if it added much...