bugfixes and code restructure

fixed duds within duds being detected, reorganised code into multiple
files