fixed the biggest parts of this small tweaking from here