Various fixes and added robustness to bad arguments