added SQL connection + log refactoring