a better error handlign. most likely not perfect.