this is quite complex method for my taste...