general changes and code re-organization