Tidied up envelope code (now scales to device width)