a bit more work, will fix later