Moved some common functionality into a separate file for future reuse