Fix hanging on windows and allow target to be specified explicitly