final code

submitted for my MS thesis
delete