Added insert/update functionality, fixed minor bugs,