some cleanup to make code more reusable