[FEATURE] Improved logic and error handling