Added bug fixes and updated memory alloc to be a ulong count.