working printing function