code refactoring and added pg composite type support