fix width calculation and id generation