Fixed infinite loop, added support to specify directory