Added several new features to the base code

I added alot of new function compared to the last version. The code is
far from perfect but its a better skeleton than the previous version.
More frequent updates will be made now using this code as a base.