still faulty; tidied up unused code