better error handling
fixed segfault caused by incorrect use of sizeof operator
forgot to change one line