Make slightly more robust and extensible