big cleanup of code