Fixed bugs in gap buffer and added more tests