restructured and new functions