first upload - this code is a mess but it does seem to run