Enhancements: logic cleared, bug fixed