added more code from bartschat