Moved some code up into a different method