Improve function
Add exception