Added exception handling for IllegalStateException