refactoring code for first step: register
try for database connection