simplified pack functions, made some variables local