fixed a bug while allocating memory