refactored insertions related code