using standard free and minor cleanup