refactored code and added fixed style, added insertValue