integrated some ideas from horst