Fixed error in database query and applied some best practices for the database queries
Merge pull request #8 from jrfnl/master

Fixed error in database query and applied some best practices