[+] added error checking and exception handling