refactor model dependencies
properly close connection
add comments