General cleanup, better logging, probs needs testing