better error Handling and some context detection