added an automatic type conversion based on DB introspection. Some code refactoring