add input flexibility
speed-up and save memory