fix bug in sqlite statements and permissions issues