adding cli support and fixing logic