Combined my current code with andreas'