Moved some code to its own private method