needs fixes, uses NULL detection which doesn't work