much more robust
updated todo