move things arround and fix 32 bit int overflow issues