remove unused code
reorder and cleanup usage, add copyright notices