now all working except a couple undefined errors