Fixed some buggery o make it more robust