better nan handling, attempts at speeding up code, setclass support