Some error handles and code merges