General cleanup, fix int overflow