fixed bug with uninitialised variables