Minor optimizations + Unit tests + Documentation + Cosmetics