lots of cleanup to make things a bit more structurally sound