Buggy version with some break-down into classes.