Cleaned up the code a bit
remove dependency on 0.13-rc1
Rearranged some code so its more apparent where it is used