Merged changes from SANdood's branch.