Bug fix, rewrite madness