Updated script for more general usage