completed q but no doubt it has bugs