more changes, some of the code is quite messy, we might want to clean up soon.