Refactor actionlog queries