Moved question generating codes to a separate function