[refactor] change linking order + add error handling