fixed handling of NULL
prepare_query is now public
changed error handling