cost array added and functional