Fix numeric overflow.

Also fixed warnings and introduced make check.