Finally - fully functioning version.