cleaned up code, extracting out interfaces and classes.