Adding basic async functionality + templating

I did also beautify the code.