Improved version now working