refactoring of cassandra write method.