Added modularisation for morphing function.