Minor bug fixes

Fixed age bug in SQL query