major bugfix. props Jonas Lundman