major rework, much more flexible