diff --git a/Foreign/Ruby/Bindings.hsc b/Foreign/Ruby/Bindings.hsc
--- a/Foreign/Ruby/Bindings.hsc
+++ b/Foreign/Ruby/Bindings.hsc
@@ -90,7 +90,15 @@
 foreign import ccall "ruby_init"                 ruby_init                   :: IO ()
 foreign import ccall "ruby_finalize"             ruby_finalize               :: IO ()
 foreign import ccall "ruby_init_loadpath"        ruby_init_loadpath          :: IO ()
+#ifdef RUBY21
+foreign import ccall "rb_str_new_cstr"           c_rb_str_new2               :: CString -> IO RValue
+foreign import ccall "rb_ary_new_capa"           rb_ary_new2                 :: CLong -> IO RValue
+foreign import ccall "rb_ary_new_from_values"    rb_ary_new4                 :: CLong -> Ptr RValue -> IO RValue
+#else
 foreign import ccall "rb_str_new2"               c_rb_str_new2               :: CString -> IO RValue
+foreign import ccall "rb_ary_new2"               rb_ary_new2                 :: CLong -> IO RValue
+foreign import ccall "rb_ary_new4"               rb_ary_new4                 :: CLong -> Ptr RValue -> IO RValue
+#endif
 foreign import ccall "rb_load_protect"           c_rb_load_protect           :: RValue -> Int -> Ptr Int -> IO ()
 foreign import ccall "rb_funcall"                c_rb_funcall_0              :: RValue -> RID -> Int -> IO RValue
 foreign import ccall "rb_funcall"                c_rb_funcall_1              :: RValue -> RID -> Int -> RValue -> IO RValue
@@ -117,8 +125,6 @@
 foreign import ccall "rb_protect"                c_rb_protect                :: FunPtr (RValue -> IO RValue) -> RValue -> Ptr Int -> IO RValue
 foreign import ccall "rb_string_value_cstr"      c_rb_string_value_cstr      :: Ptr RValue -> IO CString
 foreign import ccall "rb_ary_new"                rb_ary_new                  :: IO RValue
-foreign import ccall "rb_ary_new2"               rb_ary_new2                 :: CLong -> IO RValue
-foreign import ccall "rb_ary_new4"               rb_ary_new4                 :: CLong -> Ptr RValue -> IO RValue
 foreign import ccall "rb_ary_push"               rb_ary_push                 :: RValue -> RValue -> IO RValue
 foreign import ccall "rb_ary_entry"              rb_ary_entry                :: RValue -> CLong -> IO RValue
 foreign import ccall "rb_hash_foreach"           rb_hash_foreach             :: RValue -> FunPtr a -> RValue -> IO ()
diff --git a/Foreign/Ruby/Helpers.hs b/Foreign/Ruby/Helpers.hs
--- a/Foreign/Ruby/Helpers.hs
+++ b/Foreign/Ruby/Helpers.hs
@@ -129,7 +129,7 @@
                 return Nothing
 
 instance ToRuby Scientific where
-    toRuby s | base10Exponent s == 0 = toRuby (coefficient s)
+    toRuby s | base10Exponent s >= 0 = toRuby (coefficient s)
              | otherwise = toRuby (fromRational (toRational s) :: Double)
 
 instance ToRuby Value where
diff --git a/Setup.hs b/Setup.hs
--- a/Setup.hs
+++ b/Setup.hs
@@ -1,2 +1,61 @@
 import Distribution.Simple
-main = defaultMain
+import Distribution.Verbosity
+import Distribution.Simple.Configure
+import Distribution.Simple.LocalBuildInfo
+import Distribution.Simple.Utils
+import Distribution.PackageDescription
+import System.Environment
+
+getBuildInfo :: LocalBuildInfo -> BuildInfo
+getBuildInfo l = case library (localPkgDescr l) of
+                     Just x -> libBuildInfo x
+                     Nothing -> error "Could not find the buildinfo!"
+
+setBuildInfo :: LocalBuildInfo -> BuildInfo -> LocalBuildInfo
+setBuildInfo l b = l { localPkgDescr = lpd' }
+    where
+        lpd = localPkgDescr l
+        Just li = library lpd
+        li' = li { libBuildInfo = b }
+        lpd' = lpd { library = Just li' }
+
+main :: IO ()
+main = defaultMainWithHooks myhooks
+    where
+        myhooks    = simpleUserHooks { confHook = (\a b -> configure a b >>= myConfHook) }
+        myConfHook h = do
+            let buildinfos = getBuildInfo h
+            -- hunt for libraries
+            let rubies = ["ruby2.1", "ruby2.0", "ruby1.9", "ruby1.8", "ruby"]
+                pathes = ["/usr/lib", "/usr/local/lib"]
+                inc21 = ["/usr/include/ruby-2.1.0", "/usr/include/x86_64-linux-gnu/ruby-2.1.0", "/usr/include/ruby-2.1.0/x86_64-linux"]
+                inc20 = ["/usr/include/ruby-2.0.0", "/usr/include/x86_64-linux-gnu/ruby-2.0.0", "/usr/include/ruby-2.0.0/x86_64-linux"]
+                inc19 = ["/usr/lib/ruby/1.9/x86_64-linux"]
+                inc18 = ["/usr/lib/ruby/1.8/x86_64-linux"]
+                r21 = ("ruby2.1", inc21, ["-DRUBY2","-DRUBY21"])
+                r20 = ("ruby2.0", inc20, ["-DRUBY2"])
+                r19 = ("ruby1.9", inc19, [])
+                r18 = ("ruby1.8", inc18, [])
+            f <- findFirstFile (\(p,r) -> p ++ "/lib" ++ r ++ ".so") [(p,r) | p <- pathes, r <- rubies]
+            let rubystring = maybe "" snd f
+                lg s = notice normal ("Auto detected " ++ s)
+            (e,i,c) <- case fmap snd f of
+                           Just "ruby2.1" -> lg rubystring >> return r21
+                           Just "ruby2.0" -> lg rubystring >> return r20
+                           Just "ruby1.9" -> lg rubystring >> return r19
+                           Just "ruby1.8" -> lg rubystring >> return r18
+                           Just "ruby" -> do
+                                is21 <- findFirstFile id inc21
+                                is20 <- findFirstFile id inc20
+                                is19 <- findFirstFile id inc19
+                                is18 <- findFirstFile id inc18
+                                case filter ((/= Nothing) . fst) [(is21,r21), (is20,r20), (is19,r19), (is18,r18)] of
+                                    ((_,(n,inc,flgs)):_) -> lg n >> return ("ruby",inc,flgs)
+                                    _ -> die "Could not find the ruby library"
+                           Just x -> die $ "Did find this (this should not happen): " ++ x
+                           _ -> die "Could not find the ruby library"
+            let bi = buildinfos { extraLibs = e : extraLibs buildinfos
+                                , includeDirs = includeDirs buildinfos ++ i
+                                , ccOptions = ccOptions buildinfos ++ c
+                                }
+            return (setBuildInfo h bi)
diff --git a/cbits/shim.h b/cbits/shim.h
--- a/cbits/shim.h
+++ b/cbits/shim.h
@@ -1,4 +1,7 @@
 #include <ruby.h>
+#ifdef RUBY21
+#include <ruby/intern.h>
+#endif
 
 struct s_dispatch {
 	char * classname;
diff --git a/hruby.cabal b/hruby.cabal
--- a/hruby.cabal
+++ b/hruby.cabal
@@ -2,7 +2,7 @@
 --  see http://haskell.org/cabal/users-guide/
 
 name:                hruby
-version:             0.2.0
+version:             0.2.3
 synopsis:            Embed Ruby in your Haskell program.
 description:         Warning: this is completely experimental. Everything you need should be in "Foreign.Ruby".
 license:             BSD3
@@ -11,17 +11,9 @@
 maintainer:          bartavelle@gmail.com
 -- copyright:           
 category:            Language
-build-type:          Simple
+build-type:          Custom
 cabal-version:       >=1.8
 
-Flag Ruby20
-    Description: Enable when you use Ruby 2.0. It will default to Ruby 1.8.
-    Default: False
-
-Flag Ruby19
-    Description: Enable when you use Ruby 1.9 (not implemented yet). It will default to Ruby 1.8.
-    Default: False
-
 source-repository head
   type: git
   location: git://github.com/bartavelle/hruby.git
@@ -31,7 +23,7 @@
   exposed-modules:      Foreign.Ruby, Foreign.Ruby.Bindings, Foreign.Ruby.Helpers, Foreign.Ruby.Safe
   ghc-options:          -Wall
   extensions:           BangPatterns, OverloadedStrings
-  build-depends:        base ==4.6.*
+  build-depends:        base >= 4.6 && < 4.8
                         , aeson                == 0.7.*
                         , bytestring           >= 0.10.0.2
                         , text                 >= 0.11
@@ -43,17 +35,6 @@
   c-sources:            cbits/shim.c
   install-includes:     cbits/shim.h
   include-dirs:         cbits
-  if flag(ruby20)
-      extra-libraries:      ruby
-      cc-options:           -DRUBY2
-      include-dirs:         /usr/include/ruby-2.0.0, /usr/include/ruby-2.0.0/x86_64-linux
-  else
-      if flag(ruby19)
-          extra-libraries:      ruby1.9
-          include-dirs:         /usr/lib/ruby/1.9/x86_64-linux
-      else
-          extra-libraries:      ruby1.8
-          include-dirs:         /usr/lib/ruby/1.8/x86_64-linux
 
 Test-Suite test-roundtrip
   hs-source-dirs: test
diff --git a/test/roundtrip.hs b/test/roundtrip.hs
--- a/test/roundtrip.hs
+++ b/test/roundtrip.hs
@@ -29,7 +29,7 @@
 b = fmap Bool arbitrary
 
 n :: Gen Value
-n = fmap Number arbitrary
+n = fmap (Number . fromIntegral) (arbitrary :: Gen Integer)
 
 h :: Gen Value
 h = fmap object $ do
