Near working version, test needed