file writing worked finally. need to fix bugs in values