refactor dependency tree into function

1) write and use packageBuildOrder in Main.hs

2) write tests
remove debug line
remove debug line