cleaned up code, removed unused variables and included ioctl.h
added segfault caution