clean up code, add variable for max length instead of hardcode