Changed length data type to short (this should fix most heap overflow problems).