Fixed some offsets in alloc_mem routine that would cause subsequent calls to check wrong locations, or not realizing no memory is free. Also, added some indentation after some IF*s