Added data adapter support and refactored code