up - complete working version in c