added gdb support, refactored code