Added test for multiple directory build.
Fixed multiple-directory bug and cleaned up the code a little bit.