Moved duplicate code to Shared class.