cleaned up code, added more sophisticated (interactive) stuff