fixed some bugs and made it prettier.
fixed a pesky segfault.