Script functional, but ugly