Refactoring select and insert methods