this is slightly messy but should work