Made dyanamic allocation of array and added documentation