using melt and cast instead of reshape