Input validation

Helper classes, some bug fixes (like uniformity and consistency).