fixed small issue with order of checks in factory method