Just some preliminary coding 

I haven't tested anything yet. Its far from complete.