Fixed ref counting bug, minor formatting