Properly parsing DB query results
Changed query to keep type information
Implemented check for distance between events