restructured and fixed for new libs