Fixed some bugs and some code

Fixed double disconnect exception. Made sure allocated memory was really
allocated and corrected some code to fit FORTE syntax