more help from Daniel, re-structure of code, DON'T touch it!