updated for 6.0.1, nicer arrangement of code
updated for 6.0.1