Refactor factory build method. Added tests for api methods.