Moved common code to header file