added database query function
added logging
changed account_code to account_id everywhere