Expand function fully functional and completed with debugging flags