Refactor model layer. Update pa165.sql file.