Some code-cleaning done. More to come. TODO: Use splint