refactoring, making it more robust, also adding bignum support for int cases