Add factory spec pattern and fix bug in finding source files from source file