Input validation added
Exception handling added