added exception handling and implemented other methods