added some code from elib