cleanup, fixes and raw sql removed