Fixed deprecated function. Fixes #1
Added some bug fixes