Remove unneeded macros and add some integer overflow checks