code cleanup to better structure