updated for more robustness