Enhancement: write robuster code