fix position reset after insertion.
add error handling.