Adaptive layout

Fixed #11, #8, #7.