Fixed #321
updated #321
updated #311 for Debian
Fixed #320: add proper header and cleanup