Various fixes; update to 0.4.0