First version. Needs more errorhandling to work good