First hack at a derivative script - very incomplete