Removed unecessary lines
Added weights to optimization