Tidy up

- fix trailing whitespaces
- simplify code a little (there is much more places for tiding up now)